package xyz.scootaloo.oj.offer

import org.junit.Test

/**
 * @author flutterdash@qq.com
 * @since 2021/4/9 16:52
 */
class P16 {

    private fun myPow(x: Double, n: Int): Double {
        if (n == 0) return 1.0
        if (n == 1) return x
        if (n == -1) return (1 / x)
        val half = myPow(x, n / 2)
        val remain = myPow(x, n % 2)
        return half * half * remain
    }

    @Test
    fun test0() {
        println(myPow(2.0, 10))
        println(myPow(2.1, 3))
        println(myPow(2.0, -2))
        println(myPow(0.00001, 2147483647))
    }

}
